package cn.trip.biz.controller;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.vo.ItripImageVO;
import cn.itrip.common.RedisUtil;
import cn.trip.biz.service.HotelService;
import cn.trip.biz.service.ItripHotelService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "api/hotel")
public class HotelController {
    @Resource(name = "HotleService")
    private HotelService hotelService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ItripHotelService itripHotelService;


    /**
     * 查询热门城市
     *
     * @param type
     * @return
     */
    @ApiOperation(value = "查询热门城市", httpMethod = "GET", produces = "application/json",
            notes = "查询国内、国外的热门城市(1:国内 2:国外)")
    @RequestMapping(value = "/queryhotcity/{type}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotCity(@PathVariable Integer type) {
        Dto dto = hotelService.selectByisChina(type);
        return dto;
    }

    /**
     * 查询酒店特色列表
     *
     * @return
     */
    @ApiOperation(value = "查询酒店特色列表", httpMethod = "GET", produces = "application/json",
            notes = "获取酒店特色(用于查询页列表)")
    @RequestMapping(value = "/queryhotelfeature", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotelFeature() {
        Dto dto = null;
        try {
            dto = hotelService.selectByid(16L);
        } catch (Exception e) {
            dto = new Dto();
            dto.setSuccess("false");
            dto.setMsg("系统异常,获取失败");
        }

        return dto;
    }


    /**
     * 获取酒店图片
     *
     * @param hotelId
     * @param request
     * @return
     */
    @ApiOperation(value = "获取酒店图片", httpMethod = "GET", produces = "application/json",
            notes = "评论内获取酒店图片")
    @RequestMapping(value = "/getimg/{hotelId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto<List<ItripImageVO>> getImg(@PathVariable String hotelId, HttpServletRequest request) {
        Dto<List<ItripImageVO>> dto = null;
        String token = request.getHeader("token");
        if (redisUtil.hasKey(token)) {
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("type", "0");
            param.put("targetId", new Long(hotelId));
            dto = itripHotelService.getItripImage(param);
        } else {
            dto = new Dto();
            dto.setSuccess("false");
            dto.setMsg("token已失效");
        }
        return dto;
    }


    /**
     * 获取酒店详情
     *
     * @param hotelId
     * @return
     */
    @ApiOperation(value = "获取酒店详情", httpMethod = "GET", produces = "application/json",
            notes = "评论内获取酒店详情")
    @RequestMapping(value = "/queryhoteldetails/{hotelId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto queryhoteldetails(@PathVariable Long hotelId) {
        return itripHotelService.getHotelDetails(hotelId);
    }

    /**
     * 获取酒店设施
     *
     * @param hotelId
     * @return
     */
    @ApiOperation(value = "获取酒店设施", httpMethod = "GET", produces = "application/json",
            notes = "评论内获取酒店设施")
    @RequestMapping(value = "/queryhotelfacilities/{hotelId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto queryhotelfacilities(@PathVariable Long hotelId) {
        return itripHotelService.getHotelFaclities(hotelId);
    }

    /**
     * 获取酒店政策
     *
     * @param hotelId
     * @return
     */
    @ApiOperation(value = "获取酒店政策", httpMethod = "GET", produces = "application/json",
            notes = "评论内获取酒店政策")
    @RequestMapping(value = "/queryhotelpolicy/{hotelId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto queryhotelpolicy(@PathVariable Long hotelId) {
        return itripHotelService.getHotelPolicy(hotelId);
    }

    /**
     * 获取酒店视频介绍
     *
     * @param hotelId 目的：返回所处商圈，酒店特色，名称
     * @return
     */
    @ApiOperation(value = "获取酒店视频介绍", httpMethod = "GET", produces = "application/json",
            notes = "获取酒店视频介绍")
    @RequestMapping(value = "/getvideodesc/{hotelId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto getvideodesc(@PathVariable Long hotelId) {
        return itripHotelService.getVideoDesc(hotelId);

    }

    /**
     * 获取商圈
     *
     * @param parent
     * @return
     */
    @ApiOperation(value = "获取商圈", httpMethod = "GET", produces = "application/json",
            notes = "获取商圈")
    @RequestMapping(value = "/querytradearea/{parent}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto querytradearea(@PathVariable Long parent) {
        Long isTradingArea = 1L;
        return itripHotelService.getTradeArea(parent, isTradingArea);
    }


}
